**constructing dependent variable - explicit response
gen resp_indiv_dum=0 if resp_indiv==0 | resp_indiv==1
replace resp_indiv_dum=1 if resp_indiv_dum==.

**constructing dependent variable - substantive response
gen resp_indiv_alldum=0 if resp_indiv==0 & indirect_indiv==0 | resp_indiv==1 & indirect_indiv==0
replace resp_indiv_alldum=1 if resp_indiv_alldum==.

**converting race_rep dummy variables to a categorical variable
gen race_rep=1 if race_rep_white==1
replace race_rep=2 if race_rep_black==1
replace race_rep=3 if race_rep_other==1

**converting const_race dummy variables to a categorical variable
gen const_race=1 if const_white==1 
replace const_race=2 if const_black==1
replace const_race=3 if const_asian==1|const_latino==1|const_other==1 

**converting city dummy variables to a categorical variable
gen city=1 if city_a==1
replace city=2 if city_b==1
replace city=3 if city_c==1

**mayor variable
gen mayor=1 if rep==1| rep==18|rep==24
replace mayor=0 if mayor==.

**dropping variables
drop if const==1
drop if race_rep_other==1
drop if const_race==3

**Cross Random Effects Logit Model
xtmelogit resp_indiv_alldum i.const_race##i.race_rep || _all: R.rep || const:, mle nolog
xtmelogit resp_indiv_alldum i.const_race##i.race_rep const_gender gender_rep speak_legis content_race content_class domin_topic same_opinion mayor i.city || _all: R.rep || const:, mle nolog
xtmelogit resp_indiv_alldum i.race_rep##i.content_race const_race const_gender gender_rep speak_legis content_class domin_topic same_opinion mayor i.city || _all: R.rep || const:, mle nolog
xtmelogit resp_indiv_alldum i.race_rep##i.content_race##i.const_race const_gender gender_rep speak_legis content_class domin_topic same_opinion mayor i.city || _all: R.rep || const:, mle nolog
margins content_race##const_race, over(race_rep) at(const_gender=1 same_opinion=0 speak_legis=1 gender_rep=1 content_class=0 domin_topic=1 mayor=0 city=2) predict(mu fixedonly)
margins r.content_race@const_race, over(race_rep) at(const_gender=1 same_opinion=0 speak_legis=1 gender_rep=1 content_class=0 domin_topic=1 mayor=0 city=2) predict(mu fixedonly)
marginsplot, recast(bar) by(race_rep)

xtmelogit resp_indiv_alldum i.race_rep##i.speak_legis##i.content_race i.const_race const_gender gender_rep content_class domin_topic same_opinion mayor i.city || _all: R.rep || const:, mle nolog
margins content_race##speak_legis, at(const_race=1 const_gender=1  race_rep=1 gender_rep=1 content_class=0 domin_topic=0 same_opinion=0 mayor=0 city=2) predict(mu fixedonly)
margins r.content_race@speak_legis, at(const_race=1 const_gender=1  race_rep=1 gender_rep=1 content_class=0 domin_topic=0 same_opinion=0 mayor=0 city=2) predict(mu fixedonly)
marginsplot, recast(bar)

xtmelogit resp_indiv_alldum i.race_rep##i.const_race##i.speak_legis const_gender gender_rep i.content_race content_class domin_topic same_opinion mayor i.city || _all: R.rep || const:, mle nolog
margins const_race##speak_legis, over(race_rep) at(const_gender=1  gender_rep=1 content_race=0 content_class=0 domin_topic=0 same_opinion=0 mayor=0 city=2) predict(mu fixedonly)
margins r.const_race@speak_legis, over(race_rep) at(const_gender=1  gender_rep=1 content_race=0 content_class=0 domin_topic=0 same_opinion=0 mayor=0 city=2) predict(mu fixedonly)
marginsplot, recast(bar) by(race_rep)

**Alternative Explanations 
*(Explicit Response) 
xtmelogit resp_indiv_dum i.const_race##i.race_rep || _all: R.rep || const:, mle nolog
xtmelogit resp_indiv_dum i.const_race##i.race_rep const_gender gender_rep speak_legis content_race content_class domin_topic same_opinion mayor i.city || _all: R.rep || const:, mle nolog
xtmelogit resp_indiv_dum i.race_rep##i.content_race const_race const_gender gender_rep speak_legis content_class domin_topic same_opinion mayor i.city || _all: R.rep || const:, mle nolog
xtmelogit resp_indiv_dum i.race_rep##i.content_race##i.const_race const_gender gender_rep speak_legis content_class domin_topic same_opinion mayor i.city || _all: R.rep || const:, mle nolog

*(Ward Control Variable)
xtmelogit resp_indiv_alldum i.const_race##i.race_rep const_gender gender_rep speak_legis content_race content_class domin_topic same_opinion mayor i.city i.ward_rep || _all: R.rep || const:, mle nolog
xtmelogit resp_indiv_alldum i.race_rep##i.content_race const_race const_gender gender_rep speak_legis content_class domin_topic same_opinion mayor i.city i.ward_rep || _all: R.rep || const:, mle nolog
xtmelogit resp_indiv_alldum i.race_rep##i.content_race##i.const_race const_gender gender_rep speak_legis content_class domin_topic same_opinion mayor i.city i.ward_rep || _all: R.rep || const:, mle nolog

**appendices
*Ordered Response Variable
gen resp_indiv1=0 if resp_indiv==0
replace resp_indiv1=1 if resp_indiv==1
replace resp_indiv1=2 if resp_indiv==2|indirect_indiv==1
replace resp_indiv1=3 if resp_indiv==3

*Response with Levels of Clarification
destring clarify_indiv, force gen(clarify)
gen resp_indiv2=0 if resp_indiv_alldum==0
replace resp_indiv2=1 if resp_indiv_alldum==1 & clarify==0
replace resp_indiv2=2 if resp_indiv_alldum==1 & clarify==1

meologit resp_indiv2 i.const_race##i.race_rep const_gender gender_rep speak_legis content_race content_class domin_topic i.city mayor same_opinion || _all: R.rep || const:, nolog
margins (const_race), over(race_rep) at(const_gender=1 same_opinion=0 speak_legis=1 gender_rep=1 content_class=0 content_race=0 domin_topic=1 mayor=0 city=2) predict(outcome(0))
margins, dydx(const_race) over(race_rep) at(const_gender=1 same_opinion=0 speak_legis=1 gender_rep=1 content_class=0 content_race=0 domin_topic=1 mayor=0 city=2) predict(outcome(0))
margins (const_race), over(race_rep) at(const_gender=1 same_opinion=0 speak_legis=1 gender_rep=1 content_class=0 content_race=0 domin_topic=1 mayor=0 city=2) predict(outcome(1))
margins, dydx(const_race) over(race_rep) at(const_gender=1 same_opinion=0 speak_legis=1 gender_rep=1 content_class=0 content_race=0 domin_topic=1 mayor=0 city=2) predict(outcome(1))
margins (const_race), over(race_rep) at(const_gender=1 same_opinion=0 speak_legis=1 gender_rep=1 content_class=0 content_race=0 domin_topic=1 mayor=0 city=2) predict(outcome(2))
margins, dydx(const_race) over(race_rep) at(const_gender=1 same_opinion=0 speak_legis=1 gender_rep=1 content_class=0 content_race=0 domin_topic=1 mayor=0 city=2) predict(outcome(2))

**White Legislators Only (Response with Levels of Clarification)
drop if race_rep==2
meologit resp_indiv2 i.const_race##i.content_race i.const_gender i.gender_rep i.speak_legis i.domin_topic i.same_opinion i.mayor i.city || _all: R.rep || const:, nolog
margins r.content_race@const_race, at(const_gender=1  gender_rep=1 speak_legis=1 domin_topic=0 same_opinion=0 mayor=0 city=2) predict(outcome(0))
margins content_race##const_race, at(const_gender=1  gender_rep=1 speak_legis=1 domin_topic=0 same_opinion=0 mayor=0 city=2) predict(outcome(0))
margins r.content_race@const_race, at(const_gender=1  gender_rep=1 speak_legis=1 domin_topic=0 same_opinion=0 mayor=0 city=2) predict(outcome(1))
margins content_race##const_race, at(const_gender=1  gender_rep=1 speak_legis=1 domin_topic=0 same_opinion=0 mayor=0 city=2) predict(outcome(1))
margins r.content_race@const_race, at(const_gender=1  gender_rep=1 speak_legis=1 domin_topic=0 same_opinion=0 mayor=0 city=2) predict(outcome(2))
margins content_race##const_race, at(const_gender=1  gender_rep=1 speak_legis=1 domin_topic=0 same_opinion=0 mayor=0 city=2) predict(outcome(2))

meologit resp_indiv2 i.const_race##i.speak_legis i.content_race i.const_gender i.gender_rep i.domin_topic i.same_opinion i.mayor || _all: R.rep || const:, nolog
margins r.const_race@speak_legis, at(const_gender=1  gender_rep=1 content_race=0 domin_topic=0 same_opinion=0 mayor=0) predict(outcome(0))
margins const_race##speak_legis, at(const_gender=1  gender_rep=1 content_race=0 domin_topic=0 same_opinion=0 mayor=0) predict(outcome(0))
margins r.const_race@speak_legis, at(const_gender=1  gender_rep=1 content_race=0 domin_topic=0 same_opinion=0 mayor=0) predict(outcome(1))
margins const_race##speak_legis, at(const_gender=1  gender_rep=1 content_race=0 domin_topic=0 same_opinion=0 mayor=0) predict(outcome(1))
margins r.const_race@speak_legis, at(const_gender=1  gender_rep=1 content_race=0 domin_topic=0 same_opinion=0 mayor=0) predict(outcome(2))
margins const_race##speak_legis, at(const_gender=1  gender_rep=1 content_race=0 domin_topic=0 same_opinion=0 mayor=0) predict(outcome(2))
